package com.quanfaqiang.demo1.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quanfaqiang.demo1.anno.AddLog;
import com.quanfaqiang.demo1.anno.DeleteLog;
import com.quanfaqiang.demo1.anno.UpdateLog;
import com.quanfaqiang.demo1.pojo.Furnituretypes;
import com.quanfaqiang.demo1.pojo.Result;
import com.quanfaqiang.demo1.service.FurnituretypesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@CrossOrigin()
@RequestMapping("/furnituretypes")
public class FurnituretypesController {
    @Autowired
    private FurnituretypesService furnituretypesService;

    @GetMapping("/selectAllType")
    public Result selectAllType() {
        List<Furnituretypes> typeList = furnituretypesService.selectAllType();
        return Result.success(typeList);
    }

    @GetMapping("/selectAll")
    public Result selectAll(Integer currentPage, Integer pageSize) {
        Page<Furnituretypes> typeList = furnituretypesService.selectAll(currentPage, pageSize);
        return Result.success(typeList);
    }

    @GetMapping("/selectTypeName")
    public Result selectTypeName(String typeName) {
        Boolean flag = furnituretypesService.selectTypeName(typeName);
        System.out.println(flag);
        return Result.success(flag);
    }
    @GetMapping("/serchTypeName")
    public Result serchTypeName(String typeName,Integer currentPage, Integer pageSize) {
        System.out.println(typeName);
        Page<Furnituretypes> typeList = furnituretypesService.serchTypeName(typeName,currentPage,pageSize);
        System.out.println(typeList);
        return Result.success(typeList);
    }

    @UpdateLog
    @PostMapping("/update")
    public Result update(@RequestBody Furnituretypes type) {
        System.out.println(type);
        furnituretypesService.update(type);
        return Result.success("修改成功");
    }

    @AddLog
    @PostMapping("/add")
    public Result add(@RequestBody Furnituretypes type) {
        System.out.println(type);
        furnituretypesService.add(type);
        return Result.success("添加成功");
    }

    @DeleteLog
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        furnituretypesService.delete(id);
        return Result.success("删除成功");
    }

    @DeleteLog
    @DeleteMapping("/deleteMore/{ids}")
    public Result deleteIds(@PathVariable List<Integer> ids) {
        System.out.println(ids+"sssssssssssssssssss");
        furnituretypesService.deleteIds(ids);
        return Result.success("删除成功");
    }

}
